//
//  ViewController.m
//  BroadcastTest
//
//  Created by 赵小燕 on 16/11/29.
//  Copyright © 2016年 xiaoyanzhao. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property (nonatomic, strong) PlayerView *playerView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.view.backgroundColor = [UIColor blackColor];
    
    // 视频播放的主要类名
    // 1.AVPlayer 用于播放音视频
    // 2.AVPlayerItem 音频的对象
    // 3.AVPlayerLayer 播放显示视频的图层界面
    // 4.AVPlayerViewController 创建视频的图层,包含有调节控件
    
    // 视频播放的三个步骤
    // 1.第一部分是AVPlayer,视频播放器
    // 2.AVPlayerItem, 视频要播放的元素
    // 3.AVPlayerLayer, 视频现实的图层
    // 具体的流程是AVPlayer->AVPlayerItem->AVPlayerLayer
    
    // 1.创建需要播放的元素
//    NSURL *url = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@".m4v"];
//    AVPlayerItem *item = [AVPlayerItem playerItemWithURL:url];
//    
//    // 2.创建播放器
//    player = [AVPlayer playerWithPlayerItem:item];
//    
//    // 3.创建视频显示的图层
//    AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:player];
//    layer.backgroundColor = [UIColor blackColor].CGColor;
//
//    layer.frame = CGRectMake(10, 30, 250, 200);
//    layer.videoGravity = AVLayerVideoGravityResizeAspect;
//    
//    [self.view.layer addSublayer:layer];
//    [player play];
//    NSLog(@"11111 %f %f %f %f", layer.frame.origin.x, layer.frame.origin.y, layer.frame.size.width, layer.frame.size.height);

    
    // 使用AVPlayerViewController 播放视频
//    NSURL *url = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@".m4v"];
//    _playerViewController = [[AVPlayerViewController alloc] init];
//    _playerViewController.player = [[AVPlayer alloc] initWithURL:url];
//    _playerViewController.view.frame = CGRectMake(20, 22, 335, 300);
//    [self.view addSubview:_playerViewController.view];
//    [_playerViewController.player play];
    
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@".m4v"];
    self.playerView = [[PlayerView alloc] initWithUrl:url];
    [self.view addSubview:self.playerView];
    [self.playerView play];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
